/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jse;

import java.text.DateFormat;
import java.text.FieldPosition;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 *
 * @author WangShuai
 */
public class DateFormatTest {

    public static void main(String[] args) {
        //实际返回的是SimpleDateFormat：源代码：...return new SimpleDateFormat(timeStyle, dateStyle, loc);
        System.out.println(DateFormat.getDateInstance().format(new Date()));//default formatting style is medium      Jul 7, 2011    
        
        String strDate =   "AAAJul 6, 2011";
        ParsePosition pp = new ParsePosition(3);     //代表从第三个字符处开始解析
        System.out.println(DateFormat.getDateInstance().parse(strDate, pp));//Wed Jul 06 00:00:00 CST 2011
        //If the number of pattern letters is 3 or more, the month is interpreted as text;三个M
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MMM-dd",Locale.CHINA);  //2011-七月-07
        System.out.println(sdf.format(new Date()));
        
        SimpleDateFormat sdf2 = new SimpleDateFormat("h a (zzzz)"); 
        FieldPosition fp = new FieldPosition(DateFormat.TIMEZONE_FIELD );//跟踪返回字符串中字段的位置
        System.out.println(fp.getBeginIndex());//0
        System.out.println(sdf2.format(new Date(),new StringBuffer(),fp)); //10 AM (China Standard Time)
        System.out.println(fp.getBeginIndex());//7
       
    }
}
